﻿using System;

namespace Multiprocessing.Core.Mathematics.Matrices
{
    public class MatrixCoordinate : ICloneable, IEquatable<MatrixCoordinate>
    {
        #region Properties

        public int Column { get; private set; }

        public int Row { get; private set; }

        #endregion

        #region Constructors

        public MatrixCoordinate(int column, int row)
        {
            this.Column = column;
            this.Row = row;
        }

        #endregion

        #region Methods

        public bool Equals(MatrixCoordinate other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Column == other.Column && Row == other.Row;
        }

        public object Clone()
        {
            return new MatrixCoordinate(this.Column, this.Row);
        }

        public override bool Equals(object value)
        {
            if (ReferenceEquals(null, value)) return false;
            if (ReferenceEquals(this, value)) return true;
            if (value.GetType() != this.GetType()) return false;
            return Equals((MatrixCoordinate) value);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (Column * 397) ^ Row;
            }
        }

        public override string ToString()
        {
            return string.Format("({0}; {1})", this.Row, this.Column);
        }

        public static MatrixCoordinate Create(int row, int column)
        {
            return new MatrixCoordinate(column, row);
        }

        #endregion
    }
}
